#include "../source/server.hpp"

void OnMessage(const PtrConnection &conn, Buffer *buffer)
{
    DBG_LOG("RECV: %s", buffer->ReadPosition());
    buffer->MoveReadOffset(buffer->ReadAbleSize());
    const std::string str = "Hello World!";
    conn->Send(str.c_str(), str.size());
    // conn->Shutdown();
}

void OnClosed(const PtrConnection &conn)
{
    DBG_LOG("CLOSED CONNECTION : %p", conn.get());
}
void OnConnected(const PtrConnection &conn)
{
    DBG_LOG("NEW CONNECTION: %p", conn.get());
}
int main()
{
    TcpServer server(8080);
    server.SetThreadCount(2);
    server.EnableInactiveRelease(10);
    server.SetMessageCallback(OnMessage);
    server.SetClosedCallback(OnClosed);
    server.SetConnectedCallback(OnConnected);
    server.Start();
    return 0;
}